/*
	Port.cpp
	(c)1998 Palestar, Richard Lyle
*/

#define NOUNCONTEXTPORT_DLL
#include "stdafx.h"

#include "Port.h"
#include "Resource.h"

//----------------------------------------------------------------------------

IMPLEMENT_FACTORY( NounContextPort, Port );
REGISTER_FACTORY_KEY( NounContextPort, 4283356736651368059 );

BEGIN_PROPERTY_LIST( NounContextPort, Port )
	ADD_PROPERTY( m_Name );
	ADD_PROPERTY( m_Description );
	ADD_CLASSKEY_PROPERTY( m_Class, Noun );
	ADD_CLASSKEY_PROPERTY( m_Type, Noun );
	ADD_PORT_PROPERTY( m_Scene, ScenePort );
	ADD_PROPERTY( m_Mass );
	ADD_PROPERTY( m_Flags );
	ADD_PROPERTY( m_Resources );
	ADD_PROPERTY( m_Drops );
END_PROPERTY_LIST();

BEGIN_NAMED_PROPERTY_LIST( PLIST_NounContextPort_KeyPort, NounContextPort::KeyPort, PropertyClass );
	ADD_PROPERTY( m_sKey );
	ADD_PORT_PROPERTY( m_sPort, Port );
END_PROPERTY_LIST();

NounContextPort::NounContextPort() : Port()
{
	m_Type = CLASS_KEY(Noun);
	m_Class = CLASS_KEY(Noun);
	m_Mass = 1.0f;
	m_Flags = 0;
}

//----------------------------------------------------------------------------

const int VERSION_080801 = 80801;
const int VERSION_20041201 = 20041201;

bool NounContextPort::read( InStream &input )
{
	if (! Port::read( input ) )
		return true;

	return true;
}

//----------------------------------------------------------------------------

bool NounContextPort::autoLoad()
{
	return false;
}

void NounContextPort::dependencies( DependentArray & dep )
{
	dep.push( m_Scene );
	for(int i=0;i<m_Resources.size();i++)
		dep.push( m_Resources[ i ].m_sPort );
}

Resource::Ref NounContextPort::createResource()
{
	return initialize( new NounContext() );
}

bool NounContextPort::importFile( const char * fileName )
{
	return true;	// return true of successful import, false on failure
}

void NounContextPort::shellOpen() const
{
	MessageBox( NULL, _T("shellOpen() is not valid for this port"), NULL, MB_OK);
}

//----------------------------------------------------------------------------

NounContext * NounContextPort::initialize( NounContext * pContext )
{
	pContext->setName( m_Name );
	pContext->setDescription( m_Description );
	pContext->setScene( Scene::Link( Port::portResource( m_Scene ) ) );
	pContext->setMass( m_Mass );
	pContext->setFlags( m_Flags );

	for(int i=0;i<m_Resources.size();i++)
		pContext->addResource( m_Resources[i].m_sKey, Port::portResource( m_Resources[i].m_sPort ) );
	for(int j=0;j<m_Drops.size();++j)
		pContext->addDrop( m_Drops[j] );

	return pContext;
}

//-------------------------------------------------------------------------------
// EOF

